/*
 * Copyright (C) 2022 YLStudio.Inc
 * File Name: drv_gpio.c
 * Description: gpio函数封装
 * Version: 0.0.1
 * Author: walker2048
 */

#include <aos/hal/gpio.h>


int gpio_device_open (inode_t *node, file_t *f) {
    int ret = 0;

    return ret;
}

int gpio_device_close (file_t *f) {
    int ret = 0;

    return ret;
}

/************************** device ****************************/


subsys_file_ops_t gpio_device_fops = {
    .open = gpio_device_open,
    .close = gpio_device_close,
    .read = gpio_device_read,
    .write = gpio_device_write,
};

int gpio_device_init (struct u_platform_device *pdev) {
    // make sure 0 is returned if init operation success
    // or aos_dev_reg procedure will break and no device node will be registered
    ddkc_dbg("%s\r\n", __func__);
    return 0;
}

int gpio_device_deinit (struct u_platform_device *pdev) {
    ddkc_dbg("%s\r\n", __func__);
    return 0;
}

int gpio_device_pm (struct u_platform_device *pdev, u_pm_ops_t state) {
    ddkc_dbg("%s\r\n", __func__);
    return 0;
}

struct subsys_drv gpio_device_drv = {
    .drv_name = "gpio",
    .init = gpio_device_init,
    .deinit = gpio_device_deinit,
    .pm = gpio_device_pm,
};

struct subsys_dev g_gpio_device = {
    .user_data = NULL,
    .type = BUS_TYPE_PLATFORM,
    .permission = 0,
    .node_name = "gpio"
};

int vfs_gpio_drv_init (void) {
    int ret = 0;
    int i;

    for (i = 0; i < PLATFORM_GPIO_NUM; i++)
        gpio_hal_configs[i] = -1;

    ddkc_dbg("gpio vfs driver init starts\r\n");
    ret = aos_dev_reg(&g_gpio_device, &gpio_device_fops, &gpio_device_drv);
    if (ret) {
        ddkc_err("aos_dev_reg for uart devices failed, ret:%d\r\n", ret);
        goto err;
    }

    ddkc_dbg("gpio vfs driver init finish, ret:%d\r\n", ret);

    return 0;

err:

    ddkc_warn("gpio vfs driver init failed, ret:%d\r\n", ret);

    return ret;
}